import 'package:cloud_phone_manager/contants/Phone.dart';
import 'package:cloud_phone_manager/contants/SelfIcons.dart';
import 'package:cloud_phone_manager/utils/CmdUtils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class AdbDevicesProvider with ChangeNotifier {
  List<AdbDeviceInfo>? _adbDeviceInfo;

  List<AdbDeviceInfo> getAdbDevicesInfoList() {
    return _adbDeviceInfo ?? [];
  }

  // 外部更新数据的方法
  void updateData(List<AdbDeviceInfo> newData) {
    _adbDeviceInfo = newData;
    notifyListeners(); // 通知监听者数据发生变化
  }
}

class AdbDeviceInfo {
  //名称
  String name = "";

  //状态，离线还是在线
  bool status = false;
  String sn = "";
  String platform = "其他";
  IconData iconData = Icons.phone_android;

  AdbDeviceInfo(this.name, this.status){
    if(Phone.platform[name] != null){
      return;
    }
    CmdUtils.platform(name, (success, error, process, successListener) {
      if (success == "SM") {
        platform = "山姆";
      } else if (success == "AM") {
        platform = "AM";
      } else {
        platform = "其他";
      }
      iconData = getIcon();
      Phone.platform[name] = platform;
    });
  }

  /// 开始连接
  void connect() {
    if (name.isNotEmpty) {
      CmdUtils.connectAdb("adb connect ${name}", (success, error, process, suListener) {

      });
    }
  }

  String getPlatform() {
    return platform;
  }

  IconData getIcon(){
    if(platform == "其他"){
      return SelfIcon.word_o;
    }else if(platform == "山姆"){
      return SelfIcon.word_s;
    }else if(platform == "AM"){
      return SelfIcon.word_a;
    }
    return SelfIcon.word_o;
  }

  /// 断开连接
  void disconnect() {
    if (name.isNotEmpty) {
      CmdUtils.disconnectAdb(
          "adb disconnect ${name}", (success, error, process, suListener) {});
    }
  }
}

class DeviceHardAndSoftInfo {
  String key = "";
  String name = "";

  DeviceHardAndSoftInfo(this.key, this.name);
}
